require('../css/home.less')
require('../fonts/iconfont.css')
require('../lib/swiper/swiper-bundle.css')


document.ready(function () {
    utils.addFooter();

    var mySwiper = new Swiper('.swiper-container', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

    })

    let card = document.querySelector('.card')
    let toast = document.querySelector('.toast')
    let badgeNum = document.querySelector('.badge-num')
    let num = document.querySelector('.num')
    let punchIn = document.querySelector('.punchIn')
    let user = JSON.parse(localStorage.getItem("user"))

    function getHomeData() {
        if (user == null) {
            return
        } else {
            $http.get('//headPageInfo?userId=' + user.userId, function (res) {
                num.textContent = res.data.rank
                badgeNum.textContent = res.data.insigniaNum
                punchIn.textContent = res.data.punchIn
                if (res.data.isPunch == 'true') {
                    card.style.display = 'none';
                }
            })

        }
    }

    getHomeData()

    card.addEventListener('click', function () {
        if (user == null) {
            utils.show(1, '请先登录！')
            let timeId = setTimeout(function () {
                location.href = "../page/login.html"
            }, 2000)
        } else {
            $http.get('/clockIn?userId=' + user.userId, function (res) {
                utils.show(0, '打卡成功!')
                getHomeData()
            })
        }
    })













})